package com.mybatis.aop.serviceImpl;

import com.mybatis.aop.annotation.DataSource;
import com.mybatis.aop.dao.UserMapper;
import com.mybatis.aop.entity.User;
import com.mybatis.aop.utils.DbUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl {

    @Autowired
    UserMapper userMapper;

    public String getUser(){
    User user =userMapper.findUserByUsername("dalaoyang");
        return user!=null ? "dalaoyang"+"的密码是："+user.getuserPassword():"不存在用户名为"+"dalaoyang"+"的用户";
    }

    public String setUser(){
        User user =userMapper.findUserByUsername("xiaoli");
        return user!=null ? "xiaoli"+"的密码是："+user.getuserPassword():"不存在用户名为"+"xiaoli"+"的用户";
    }

    public String ALLUser(){
        List<User> userList =userMapper.getUserList();
        return userList.toString() ;
    }

    @DataSource(DbUtil.DB_MASTER2)
    public String findUser(){
        User user =userMapper.findUserByUsername("xiaoxiongmao");
        System.out.println(user.toString());
        return user!=null ? "xiaoxiongmao"+"的密码是："+user.getuserPassword():"不存在用户名为"+"xiaoxiongmao"+"的用户";
    }



}
